package com.tender;

import com.tender.utils.ESOperationTemplate;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;

public class A_9_BatchDeleteDoc {

    public static void main(String[] args) throws Exception {
        ESOperationTemplate.process(client -> {

            try {
                //创建批量删除请求对象
                BulkRequest request = new BulkRequest();
                request.add(new DeleteRequest().index("user2").id("1001"));
                request.add(new DeleteRequest().index("user2").id("1002"));
                request.add(new DeleteRequest().index("user2").id("1003"));
                //客户端发送请求，获取响应对象
                BulkResponse responses = client.bulk(request, RequestOptions.DEFAULT);
                //打印结果信息
                System.out.println("took:" + responses.getTook());
                System.out.println("items:" + responses.getItems());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return null;
        });
    }

}
